import {getAllByPage, del, delAll} from '@/services/system/SysLog';
import {message} from 'antd';

export default {
  namespace: 'PSystemLog',

  state: {
    dataTable: {
      total: 0,
      list: [],
    },
  },

  effects: {
    * getAllByPage({payload}, {call, put}) {
      const response = yield call(getAllByPage, payload);
      if (response.code === 0) {
        yield put({
          type: 'chgDataTable',
          payload: response.data,
        });
      }
    },

    * del({payload, callback}, {call}) {
      const response = yield call(del, payload);
      if (response.code === 0) {
        message.success('删除成功').then();
        callback && callback();
      }
    },

    * delAll({callback}, {call}) {
      const response = yield call(delAll);
      if (response.code === 0) {
        message.success('清空成功').then();
        callback && callback();
      }
    },

  },

  reducers: {
    chgDataTable(state, action) {
      return {
        ...state,
        dataTable: action.payload,
      };
    },
  },
};
